<!-- 字典管理 -->
<template>
  <div class="content">
    <!-- 筛选栏 -->
    <search-form
      ref="searchForm"
      :dataFilterShow="false">
      <div>
        <el-form-item label="字典类型:" prop="type">
          <el-input
            v-model="filterData.type"
            clearable
            placeholder="字典类型"
          ></el-input>
        </el-form-item>
      </div>
      <div slot="tool">
        <el-button type="primary" @click="upDateDic(1,{})">新增字典</el-button>
        <el-button @click="getDataList">查询</el-button>
      </div>
    </search-form>

    <!-- 列表栏 -->
    <filter-table
      :tableData="dataList.records"
      :pageData="dataList"
      @pageChange="pageChange"
      :loading="loading"
      ref="refFilterTable"
    >
      <template slot="table">
        <el-table-column prop="id" label="字典Id"></el-table-column>
        <el-table-column prop="dictKey" label="字典Key"></el-table-column>
        <el-table-column prop="value" label="字典值" show-overflow-tooltip></el-table-column>
        <el-table-column prop="type" label="字典类型"></el-table-column>
        <el-table-column prop="remark" label="备注" show-overflow-tooltip></el-table-column>
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100">
          <template slot-scope="{row}">
            <el-button type="text" @click="upDateDic(2,row)">编辑</el-button>
          </template>
        </el-table-column>
      </template>
    </filter-table>
    <!-- 新增编辑字典 -->
    <update-dic
      ref="updateDeptDialog"
      :isAdd="isAdd"
      :detailData="deptData"
      :addEditVisible="addEditVisible"
    ></update-dic>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { parseTime, formatTime } from '@/utils'
import SearchForm from '@/components/searchForm/searchTable'
import FilterTable from '@/components/filterTable/index'
import { getDictPagelList } from '@/api/rightsManage'
import updateDic from './components/updateDic'
export default {
  name: 'roleList',
  components: { SearchForm, FilterTable , updateDic},
  computed: {
    ...mapGetters(['name', 'userInfo'])
  },
  data() {
    return {
      loading:false,
      exportButtomLoading: false,
      addEditVisible: false,
      isAdd: 1,
      deptData: {},
      filterData: {
        type: ''
      },
      pagination: {
        page: 1,
        total: null,
        limit: 20
      },
      dataList: [],
      newDataList:[],
    }
  },
  created() {},
  mounted() {
    this.getDataList()
  },
  methods: {
    // 获取列表数据
    getDataList() {
      this.loading = true
      getDictPagelList(Object.assign({}, this.filterData , this.pagination )).then(res => {
        this.loading = false
        this.dataList = res.data
      })
    },
    // 新增编辑字典
    upDateDic(type, item) {
      this.isAdd = type
      this.deptData = Object.assign({}, item)
      this.$refs.updateDeptDialog.addEditVisible = true
    },
    // 分页联动
    pageChange(pagedata) {
      setTimeout(() => {
        this.pagination = pagedata
      }, 1)
    },
  },
  watch: {
    filterData: {
      deep: true,
      handler(now, old) {
        this.pagination.page===1?this.getDataList():(this.pagination.page=1);
      }
    },
    pagination: {
      deep: true,
      handler(now, old) {
        this.getDataList()
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>





